# -*- coding: utf-8 -*-
"""
Created on Wed Aug  7 17:24:43 2019

@author: zhryyshr
"""
# In[]
import numpy as np  #计算库
import numpy.random as npr  #随机数
import matplotlib.pyplot as plt  #绘图
# In[]    模拟
npr.seed(2000)
S0 = 100
r = 0.05
sigma = 0.25
T = 2.0
I = 10000
M = 50
dt = T/M
S = np.zeros((M+1, I))
S[0] = S0
for t in range(1, M+1):
    S[t] = S[t-1] * np.exp((r-0.5 * sigma ** 2) * dt + sigma * np.sqrt(dt) * npr.standard_normal(I))
#密度直方图
plt.figure(figsize = (15,10))
plt.hist(S[-1], bins = 50)
plt.xlabel('index level')
plt.ylabel('frequency')
plt.grid(True)
#模拟路径
plt.figure(figsize = (15,10))
plt.plot(S[: , :], lw = 1.5)
plt.xlabel('time')
plt.ylabel('index level')
plt.grid(True)
for i in range(0,I):
    C=max([S[-1]-100,0])
# In[]    绘图
import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.mplot3d import Axes3D

fig,axes = plt.subplots(2,2,figsize=(15,15))


plt.show()

fig,axes=plt.subplots(2,2, figsize=(10,10))
#simple plots
t = np.arange(0.0, 2.0, 0.01)
s = 1 + np.sin(2 * np.pi * t)
axes[0,0].plot(t,s)
axes[0,0].set_title('simple plot')
#histograms
np.random.seed(20180201)
s=np.random.randn(2,50)
axes[0,1].hist(s[0])
axes[0,1].set_title('histogram')
#scatter plots
axes[1,0].scatter(s[0],s[1])
axes[1,0].set_title('scatter plot')
#pie charts
labels = 'Taxi', 'Metro', 'Walk', 'Bus','Bicycle','Drive'
sizes = [10, 30, 5, 25, 5, 25]
explode = (0, 0.1, 0, 0, 0, 0)
axes[1,1].pie(sizes, explode=explode, labels=labels, autopct='%1.1f%%',
        shadow=True, startangle=90)
axes[1,1].axis('equal')
axes[1,1].set_title('pie chart');
plt.savefig('figure.svg')
plt.show()



